# New ports collection makefile for:	oracle-xe
# Date created:		2008-03-09
# Whom:			Adrian Penisoara <ady@freebsd.ady.ro>
#
# $FreeBSD$
#

PORTNAME=	oracle-xe-${ORACLEVERSION}
PORTVERSION=	1.0
CATEGORIES=	databases linux
MASTER_SITES=	# fetch manually
PKGNAMEPREFIX=	linux-
EXTRACT_SUFX=	.i386.rpm
DIST_SUBDIR=	oracle
WRKSRC=		${WRKDIR}

MAINTAINER=	ady@freebsd.ady.ro
COMMENT=	Oracle Database 10g Release 2 Express Edition for Linux

EXTRACT_DEPENDS=	${RPM2CPIO}:${PORTSDIR}/archivers/rpm
RUN_DEPENDS=	${LINUXBASE}/usr/lib/libaio.so.1:${PORTSDIR}/emulators/linux-libaio

RPM2CPIO?=	${LOCALBASE}/bin/rpm2cpio
EXTRACT_CMD=	${RPM2CPIO}
EXTRACT_BEFORE_ARGS=
EXTRACT_AFTER_ARGS=	| ${CPIO} -id --quiet

RESTRICTED=	Packaging prohibited by Oracle license
ONLY_FOR_ARCHS=	i386
USE_LINUX=	fc4
NO_BUILD=	yes
#BRANDELF_DIRS=	${ORACLEHOME}/bin

OPTIONS=	BSDHIER "Force BSD layout hierarchy (using symlinks)" off \
		LINUXROOT "Use Linux compat root (under /compat/linux)" off

MAN1=		exp.1 imp.1 impdp.1 oracle.1 sqlldr.1 sqlplus.1
MANCOMPRESSED=	yes
USE_RC_SUBR=	yes
PLIST_SUB=	ORACLEPREFIX=${ORACLEPREFIX} \
		ORACLEUSER=${ORACLEUSER} ORACLEGROUP=${ORACLEGROUP}

ORACLEVERSION=	10.2.0.1
ORACLEDEFBASE=	/usr/lib/oracle
ORACLEBASE?=	${ORACLEDEFBASE}
ORACLEHOME=	${ORACLEBASE}/xe/app/oracle/product/10.2.0/server
ORACLESWDIR?=	${PREFIX}/oracle
ORACLEDBDIR?=	/var/db/oracle
ORACLEBKPDIR?=	/var/backups/oracle
ORACLEUSER?=	oracle
ORACLEGROUP?=	dba

.if defined(WITH_LINUXROOT)
USE_LINUX_PREFIX=	yes
.endif

.include <bsd.port.pre.mk>

.if defined(WITH_LINUXROOT)
ORACLEBASE=	${PREFIX}${ORACLEDEFBASE}
ORACLEPREFIX=	${ORACLEBASE:S|/oracle$||}
MANPREFIX=	${PREFIX}/usr/share
.elif defined(WITH_BSDHIER)
ORACLEPREFIX=	${PREFIX}
.else
ORACLEPREFIX=	${ORACLEBASE:S|/oracle$||}
.endif

.if !exists(${DISTDIR}/${DIST_SUBDIR}/${DISTNAME}${EXTRACT_SUFX})
ECHO_MSG=	${PRINTF} %b

IGNORE+=	\n\n
IGNORE+=	Due to Oracle license restrictions, you must fetch the distribution \n
IGNORE+=	file manually. Please access \n
IGNORE+=	http://www.oracle.com/technology/software/products/database/xe/htdocs/102xelinsoft.html \n
IGNORE+=	with a modern web browser and follow the download link for \n
IGNORE+=	\"${DISTFILES}\". \n
IGNORE+=	You will be required to register an account and log in. \n
IGNORE+=	\n
IGNORE+=	After registration and accepting the Oracle License, \n
IGNORE+=	download the distribution file into \n
IGNORE+=	${DISTDIR}/${DIST_SUBDIR}/ \n
IGNORE+=	and then restart this installation\n\n
.endif

post-patch:
	@${SED} -i "" -e "s=%%PREFIX%%=${PREFIX}=g" \
		-e "s=%%ORACLEUSER%%=${ORACLEUSER}=g" \
		-e "s=%%ORACLEGROUP%%=${ORACLEGROUP}=g" \
		${WRKDIR}/etc/init.d/oracle-xe

pre-install:
.if !defined(BATCH) && !defined(PACKAGE_BUILDING)
	@${SETENV} PKG_PREFIX="${PREFIX}" ${SH} -x ${PKGREQ} ${PKGNAME} INSTALL
.endif

.if defined(WITH_BSDHIER) && !defined(WITH_LINUXROOT)
	${MKDIR} ${PREFIX}/oracle && \
	  ${LN} -shf ${PREFIX}/oracle ${ORACLEBASE}
.else
	${MKDIR} ${ORACLEBASE}
.endif

	@${SETENV} PKG_PREFIX="${PREFIX}" \
		ORACLEUSER=${ORACLEUSER} \
		ORACLEGROUP=${ORACLEGROUP} \
		${SH} -x ${PKGINSTALL} ${PKGNAME} PRE-INSTALL

do-install:
	cd ${WRKDIR}/usr/lib/oracle && ${FIND} . -print \
	  | ${CPIO} -pdmu -R ${ORACLEUSER}:${ORACLEGROUP} ${ORACLEBASE}
	cd ${WRKDIR}/usr/share && ${FIND} . -not -path ./man* -print \
	  | ${CPIO} -pdmu -R ${SHAREOWN}:${SHAREGRP} ${PREFIX}/share
	for i in ${MAN1:S/$/.gz/} ; do \
	  ${INSTALL_MAN} ${WRKDIR}/usr/share/man/man1/$${i} ${MANPREFIX}/man/man1; \
	done
	${INSTALL_SCRIPT} ${WRKDIR}/etc/init.d/oracle-xe ${LOCALBASE}/etc/rc.d/oracle-xe${RC_SUBR_SUFFIX}
.if defined(WITH_BSDHIER)
.if defined(ORACLEDBDIR)
	${MKDIR} ${ORACLEDBDIR} || true
	${MKDIR} ${ORACLEDBDIR}/oradata && \
	  ${LN} -shf ${ORACLEDBDIR}/oradata ${ORACLEBASE}/xe
	${MKDIR} ${ORACLEDBDIR}/admin && \
	  ${LN} -shf ${ORACLEDBDIR}/admin ${ORACLEBASE}/xe/app/oracle
	${MV} ${ORACLEHOME}/network/log ${ORACLEDBDIR}/network/ && \
	  ${LN} -shf ${ORACLEDBDIR}/network/log ${ORACLEHOME}/network
	${MV} ${ORACLEHOME}/network/trace ${ORACLEDBDIR}/network/ && \
	  ${LN} -shf ${ORACLEDBDIR}/network/trace ${ORACLEHOME}/network
	${CHOWN} -R ${ORACLEUSER}:${ORACLEGROUP} ${ORACLEDBDIR}
.endif
.if defined(ORACLEBKPDIR)
	${MKDIR} ${ORACLEBKPDIR} || true
	${MKDIR} ${ORACLEBKPDIR}/flash_recovery_area && \
	  ${LN} -shf ${ORACLEBKPDIR}/flash_recovery_area ${ORACLEBASE}/xe/app/oracle
	${CHOWN} -R ${ORACLEUSER}:${ORACLEGROUP} ${ORACLEBKPDIR}
.endif
.endif

post-install:
	@${SETENV} PKG_PREFIX="${PREFIX}" \
		ORACLEUSER=${ORACLEUSER} \
		ORACLEGROUP=${ORACLEGROUP} \
		${SH} -x ${PKGINSTALL} ${PKGNAME} POST-INSTALL
	@${CAT} ${PKGMESSAGE}

.include <bsd.port.post.mk>
